package entities;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the friends database table.
 * 
 */
@Entity
@Table(name="friends")

@NamedQueries({

@NamedQuery(name="getPendingRequests", 
	query="SELECT x FROM Friend x WHERE x.userprofile2.userId=:userId AND x.relationshipActive = 0"),

@NamedQuery(name="getRequest", 
	query="SELECT x FROM Friend x WHERE x.userprofile1.userId=:userId1 AND x.userprofile2.userId=:userId2"),
	
@NamedQuery(name="isFriend", 
	query="SELECT x.id FROM Friend x " +
			"WHERE x.relationshipActive = 1 AND ((x.userprofile1.userId=:userId1 AND x.userprofile2.userId=:userId2) OR" +
			"(x.userprofile2.userId=:userId1 AND x.userprofile1.userId=:userId2))"),
			
@NamedQuery(name="myFriends", 
		query="SELECT x FROM Friend x " +
				"WHERE x.relationshipActive = 1 AND (x.userprofile1.userId=:userId OR x.userprofile2.userId=:userId)")				
})

public class Friend implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="Id", unique=true, nullable=false)
	private int id;

	@Column(name="RelationshipActive", nullable=false)
	private Boolean relationshipActive = false;

	//bi-directional many-to-one association to Userprofile
    @ManyToOne
	@JoinColumn(name="UserIdAck", nullable=false)
	private Userprofile userprofile2;

	//bi-directional many-to-one association to Userprofile
    @ManyToOne
	@JoinColumn(name="UserIdReq", nullable=false)
	private Userprofile userprofile1;

    public Friend() {
    }

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Boolean getRelationshipActive() {
		return this.relationshipActive;
	}

	public void setRelationshipActive(Boolean relationshipActive) {
		this.relationshipActive = relationshipActive;
	}

	public Userprofile getUserprofile1() {
		return this.userprofile1;
	}

	public void setUserprofile1(Userprofile userprofile1) {
		this.userprofile1 = userprofile1;
	}
	
	public Userprofile getUserprofile2() {
		return this.userprofile2;
	}

	public void setUserprofile2(Userprofile userprofile2) {
		this.userprofile2 = userprofile2;
	}
	
}